package org.coco24.pmstudio

import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable
import com.badlogic.gdx.utils.Array
import com.kotcrab.vis.ui.VisUI
import com.kotcrab.vis.ui.util.adapter.ArrayListAdapter
import com.kotcrab.vis.ui.util.adapter.ListAdapter
import com.kotcrab.vis.ui.widget.ListView
import com.kotcrab.vis.ui.widget.VisImageButton
import com.kotcrab.vis.ui.widget.VisTable
import org.coco24.pmstudio.pack.Pokemon

class PokemonListAdapter(pokemons: ArrayList<Pokemon>): ArrayListAdapter<Pokemon, PokemonListEntry>(pokemons)
{
    val tableBackground = (VisUI.getSkin().get(VisImageButton.VisImageButtonStyle::class.java).up as NinePatchDrawable).tint(if (GdxGame.R.PPI < 128) Color.WHITE else Color.LIGHT_GRAY)

    override fun createView(item: Pokemon?): PokemonListEntry
    {

        val pokemonListEntry = PokemonListEntry()
        pokemonListEntry.nameLabel.setText("No.${String.format("%03d", item?.number?.internal?:0)} " + item?.name?.internal)
        return pokemonListEntry
    }

    override fun selectView(view: PokemonListEntry?)
    {
        view?.background = tableBackground
    }

    override fun deselectView(view: PokemonListEntry?)
    {
        view?.background = null
    }
}